package homework

object Job2Demo {
  def main(args: Array[String]): Unit = {
    println("----------------------------------")
    val user=new User
    val cp=new Computor
    println("请输入角色名")
    user.name=scala.io.StdIn.readLine()
    var flag=true
    while (flag){
    println("请出拳：1.剪刀 2.石头 3.布")
    val choose: String =scala.io.StdIn.readLine()
    choose match {
      case "1" => println(s"你出拳：剪刀")
      case "2" => println(s"你出拳：石头")
      case "3" => println(s"你出拳：布")
    }
    matchs(user,cp,choose)
    println("是否继续：n/y")
    val continue: String =scala.io.StdIn.readLine()
      continue match {
        case "n" =>
          {
            println("再见")
            flag=false
          }

        case "y" => println("继续")
      }
    }
    user.showFist
    cp.showFist

  }

  def matchs(user:User,cp:Computor,x:String): Unit ={
    val y =(scala.util.Random.nextInt(3)+1).toString
    y match {
      case "1" => println(s"电脑出拳：剪刀")
      case "2" => println(s"电脑出拳：石头")
      case "3" => println(s"电脑出拳：布")
    }
    if(x.equals(y)){
      println("平局")
      user.score+=1
      cp.score+=1
    }
    if (x=="1"&&y=="2"){
      println("电脑获胜")
      cp.score+=2
    }else if (x=="1"&&y=="3"){
      println(s"${user.name} 获胜")
      user.score+=2
    }else if (x=="2"&&y=="1"){
      println(s"${user.name}  获胜")
      user.score+=2
    }else if (x=="2"&&y=="3"){
      println("电脑获胜")
      cp.score+=2
    }else if (x=="3"&&y=="1"){
      println("电脑获胜")
      cp.score+=2
    }else if (x=="3"&&y=="2"){
      println(s"${user.name}  获胜")
      user.score+=2
    }

  }


}

class User {
  var name:String= _
  var score =0

  def  showFist: Unit ={
    println(s"$name  $score")
  }


}

class Computor {
  val name="电脑"
  var score =0
  def  showFist: Unit ={
    println(s"$name  $score")
  }

}
